#!/bin/bash

# INPUT ENVIRONMENT VARIABLES
echo "USER="${1}
echo "STEP="${2}

# OUTPUT ENVIRONMENT VARIABLES
echo "SLURM_JOB_ID="$SLURM_JOB_ID
echo "SLURM_JOB_NODELIST"=$SLURM_JOB_NODELIST
echo "SLURM_NNODES"=$SLURM_NNODES
echo "SLURM_SUBMIT_DIR="$SLURM_SUBMIT_DIR
echo "SLURM_ARRAY_TASK_ID="$SLURM_ARRAY_TASK_ID
echo "SLURM_ARRAY_JOB_ID"=$SLURM_ARRAY_JOB_ID
echo "SLURM_NTASKS"=$SLURM_NTASKS


# case if user has shell_profile.sh file setup (assuming that if so they have shell_module.sh too)
if [ -f ~/shell_profile.sh ];
then
    source ~/shell_profile.sh
else
    echo "Please set up ~/shell_profile.sh file. Exiting."
    exitcd
fi

# make error folder if it doesn't exist 
mkdir -p $project_path/logs/${2}

# RUN R SCRIPT
R CMD BATCH --no-save --no-restore '--args tempdir="'$project_path'/morningstar/temp/externalid" rawdir="'$project_path'/raw/externalid/latest"' $code_path/morningstar/externalid/${2}.R $project_path/logs/${2}/${1}_${2}.out

# FINISHED
echo "Finished Step "${2}
exit
